///Users/apple1/莫祥富/代码/综合项目/新浪微博/Swift版/Swift微博/Swift微博.xcodeproj
//  XFBaseViewController.swift
//  mxfweibo
//
//  Created by apple1 on 15/12/15.
//  Copyright © 2015年 莫祥富. All rights reserved.
//

import UIKit

class XFBaseViewController: UITableViewController,XFVistorViewDelegate {

    var userLogin = XFUserAccount.userLogin
    
    override func viewDidLoad() {
        super.viewDidLoad()

        userLogin ? super.loadView() : setupVistorView()
    }

    //MARK: - 创建访客视图
    func setupVistorView()
    {
        view = visitorView
        
        visitorView.delegate = self
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewRegisterClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewLoginClick")
        
        
        if self is XFHomeViewController{
            visitorView.startRotationAnimation()
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
        
        }
        else if self is XFMessageViewController{
            visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }
        else if self is XFDiscoveryViewController{
            visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }
        else if self is XFProfileViewController{
            visitorView.setupVisitorInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
    }
    
    deinit{
        if self is XFHomeViewController{
            NSNotificationCenter.defaultCenter().removeObserver(self)
        }
    }
    
    func didEnterBackground(){
    
        visitorView.pauseAnimation()
    }
    
    func didBecomeActive(){
        visitorView.resumeAnimation()
    }
     
    
    func vistorViewRegisterClick() {
        print("注册")
    }
    
    func vistorViewLoginClick() {
        let oauthVc = XFOauthViewController()
        
        presentViewController(UINavigationController(rootViewController: oauthVc), animated: true, completion: nil)
    }
    
    lazy var visitorView : XFVistorView = XFVistorView()

}
